home *** CD-ROM | disk | FTP | other *** search
/ Enciclopedia Del Perro / Enciclopedia Del Perro.iso / i-view / ivpro163.zip / CGI.ZIP / TESTCGI.C next >
C/C++ Source or Header  |  1996-06-12  |  3KB  |  90 lines

  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #include "string.h"
  4. #include "windows.h"
  5.  
  6. // Simple back-end Windows CGI test program.
  7. // This program is used as WIN CGI back-end program for I-View or other 
  8. // client applications who support WIN CGI.  It's command line must follow 
  9. // the following convension:
  10. //
  11. // Command line format:
  12. // argv[0] -- path of this back-end executable.
  13. // argv[1] -- path of the CGI data file.
  14. // argv[2] -- path to the file containing any content the was received 
  15. //            with the client(I-View)'s request, regardless of the method.
  16. // argv[3] -- path of the output file where this back-end execuble puts 
  17. //            results.
  18. // argv[4] -- anything that follows an unescaped "?" in the requested URL.
  19. //
  20. // This is just a test program.  It gets information from the command line 
  21. // arguments, reads data from the CGI data file, then writes the result to 
  22. // the output file from which the client application (such as I-View) will 
  23. // read.
  24. //
  25. //
  26. main(argc, argv)
  27. int argc;
  28. char **argv;
  29. {
  30.     char cgi_data_file[128];
  31.     char content_file[128];
  32.     char output_file[128];
  33.     char url_args[128]; 
  34.     char temp[256];
  35.     FILE *fp1, *fp2;
  36.  
  37.     // check if number of arguments is correct
  38.     if (argc != 5)
  39.         return 0;
  40.  
  41.     // get command line arguments
  42.     strcpy(cgi_data_file, argv[1]);
  43.     strcpy(content_file, argv[2]);
  44.     strcpy(output_file, argv[3]);
  45.     strcpy(url_args, argv[4]);
  46.  
  47.     // We now allow empty data file
  48.     // open CGI data file for read
  49.     //if (!(fp1 = fopen(cgi_data_file, "r")))
  50.     //    return 0;
  51.     fp1 = fopen(cgi_data_file, "r");
  52.     
  53.     // open output file for write
  54.     if (!(fp2 = fopen(output_file, "w")))
  55.     {
  56.         fclose(fp1);
  57.         return 0;
  58.     }
  59.  
  60.     // write HTML header stuff to output file
  61.     fprintf(fp2, "<HTML>\n<HEAD>\n<TITLE>Window CGI Test Results</TITLE>\n</HEAD>\n<BODY>\n");
  62.  
  63.     // write command line info to output file:
  64.     fprintf(fp2, "<H3>Your Command Line Information</H3>\n");
  65.     fprintf(fp2, "<UL>\n<LI><I>CGI Data File is</I>: %s</LI>\n", cgi_data_file);
  66.     fprintf(fp2, "<LI><I>Content File is</I>: %s</LI>\n", content_file);
  67.     fprintf(fp2, "<LI><I>Output File is</I>: %s</LI>\n", output_file);
  68.     fprintf(fp2, "<LI><I>URL arguments are</I>: %s</LI>\n</UL>\n<HR>\n", url_args);
  69.     
  70.     // here we just copy contents of CGI data file to the output file.
  71.     // in real WIN CGI back-end program, we may need to do some work 
  72.     // on the input cgi data buffer, then write results to the output
  73.     // file.
  74.     fprintf(fp2, "<H3>Content of Your CGI Data File</H3>\n");
  75.     fprintf(fp2, "<PRE>\n");
  76.     while (fp1 && fgets(temp, 256, fp1))
  77.     {
  78.         fprintf(fp2, "%s", temp);
  79.     }
  80.     fprintf(fp2, "</PRE><HR>\n");
  81.  
  82.     // write HTML stuff 
  83.     fprintf(fp2, "</BODY>\n</HTML>\n\n");
  84.     
  85.     fclose(fp2);
  86.     return 1;
  87. }
  88.  
  89.  
  90.